<?php

class GoodsModel extends CommonModel{

	//获取配件商品的父商品ID
	public function get_fittings_parentid(){
		$sql 	= 	"SELECT goods_id  FROM  `ybr_cart`  WHERE  session_id = '" . SESS_ID . "' " .
		            "AND rec_type = '" . CART_GENERAL_GOODS . "' " .
		            "AND is_gift = 0 " .
		            "AND extension_code <> 'package_buy' " .
		            "AND parent_id = 0 ";
		return self::getCol($sql);
	}
	
	//获取所有配件商品列表信息
	public function get_goods_fittings($goods_list = array()){
		$temp_index 			= 	0;
	    $arr        			= 	array();	
	    $sql 					= 	'SELECT gg.parent_id, ggg.goods_name AS parent_name, gg.goods_id, gg.goods_price, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' .
	                				"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price ".
	            					'FROM ' . ' ybr_group_goods ' . ' AS gg ' .
	            					'LEFT JOIN ' . ' ybr_goods ' . ' AS g ON g.goods_id = gg.goods_id ' .
	            					"LEFT JOIN " . ' ybr_member_price ' . " AS mp ".
	                    			"ON mp.goods_id = gg.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
						            "LEFT JOIN " . 'ybr_goods' . " AS ggg ON ggg.goods_id = gg.parent_id ".
						            "WHERE gg.parent_id " . db_create_in($goods_list) . " AND g.is_delete = 0 AND g.is_on_sale = 1 ".
						            "ORDER BY gg.parent_id, gg.goods_id";
		
	    $res 					= 	M()->query($sql);
	
	    foreach($res as $row){
	    	$arr[$temp_index]['parent_id']         = $row['parent_id'];//配件的基本件ID
	        $arr[$temp_index]['parent_name']       = $row['parent_name'];//配件的基本件的名称
	        $arr[$temp_index]['parent_short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['parent_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['parent_name'];//配件的基本件显示的名称
	        $arr[$temp_index]['goods_id']          = $row['goods_id'];//配件的商品ID
	        $arr[$temp_index]['goods_name']        = $row['goods_name'];//配件的名称
	        $arr[$temp_index]['short_name']        = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];//配件显示的名称
	        $arr[$temp_index]['fittings_price']    = price_format($row['goods_price']);//配件价格
	        $arr[$temp_index]['shop_price']        = price_format($row['shop_price']);//配件原价格
	        $arr[$temp_index]['goods_thumb']       = get_image_path($row['goods_id'], $row['goods_thumb'], true);
	        $arr[$temp_index]['goods_img']         = get_image_path($row['goods_id'], $row['goods_img']);
	        //$arr[$temp_index]['url']               = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
	        $temp_index ++;
	    }
	    return $arr;
	}
	
	
}























